package com.ry.est.util;

import com.ry.est.dto.CommonResult;

/**
 * @author ry
 * @since 2021-11-01 17:58
 **/
public class ResultUtil {
    private static <T> CommonResult<T> build(String code,String msg,T data){
        CommonResult<T> result = new CommonResult<>();
        result.setData(data);
        result.setMsg(msg);
        result.setCode(code);

        return result;
    }

    public static <T> CommonResult<T> success(String msg,T data){
        return build("0",msg,data);
    }

    public static <T> CommonResult<T> success(String msg){
        return build("0",msg,null);
    }

    public static <T> CommonResult<T> success(T data){
        return build("0","操作成功",data);
    }

    public static <T> CommonResult<T> success(){
        return build("0","操作成功",null);
    }

    public static <T> CommonResult<T> fail(String code,String msg){
        return build(code,msg,null);
    }

    public static <T> CommonResult<T> fail(){
        return build("-1","操作失败",null);
    }
}
